package org.yray.netty.v5;

import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelHandlerAdapter;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.SimpleChannelInboundHandler;
import lombok.extern.slf4j.Slf4j;
import org.apache.log4j.Logger;

import java.io.Serializable;


public class ServerHandler extends SimpleChannelInboundHandler {
    /**
     当通道被调用，执行方法(拿到数据)
     */
    private static Logger log = Logger.getLogger(ServerHandler.class);
    @Override
    public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception {
       // super.channelRead(ctx, msg);
        String value = (String) msg;
        System.out.println("服务器端收到客户端msg:"+value);
        //回复客户端
        ctx.writeAndFlush("收到msg"+value);
    }

    @Override
    protected void channelRead0(ChannelHandlerContext channelHandlerContext, Object o) throws Exception {
        System.out.println("服务器端收到客户端msg:");
    }


}
